#import "NSTreeNode+SRAdditions.h"


@implementation NSTreeNode (SRAdditions)

- (NSArray *)descendants {
   NSMutableArray *descendants = [NSMutableArray array];
   for (NSTreeNode *node in [self childNodes]) {
       [descendants addObject:node];
       if (![node isLeaf])
           [descendants addObjectsFromArray:[node descendants]];
   }
   return [[descendants copy] autorelease];
}

-(NSString *)treeDescription {
    NSString *description = [NSString stringWithString:[[self representedObject] description]];
    for (NSTreeNode *childNode in [self childNodes]) {
        description = [NSString stringWithFormat:@"%@\n%@", description, [childNode treeDescription]];
    }
    return description;
}

-(NSString *)classDescriptionAtLevel:(NSInteger)indention {
    NSString *description = [NSString stringWithFormat:@"%*s %@", (indention * 2), "-", [[self representedObject] className]];
    indention++;
    for (NSTreeNode *childNode in [self childNodes]) {
        description = [NSString stringWithFormat:@"%@\n%@", description, [childNode classDescriptionAtLevel:indention]];
    }
    return description;
}


@end
